# -*- coding: utf-8 -*-

'''eof
name:婚姻状况
code:IG03_MariState
tableName:
columnName:
groups:个人通用模块
dependencies:IC_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''


import sys
import pandas as pd
import json
from datetime import datetime


def FormatData(tableName):
    try:
        ic = IC_DSJ.get("data").get(tableName)
        return ic if isinstance(ic, list) else [{}]
    except:
        return [{}]


def getIG03():
    null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']
    marital_state_list = [u'已婚', u'未婚', u'离婚', u'丧偶']
    try:
        ICRIdentity = FormatData("ICRIdentity")
        if ICRIdentity == [{}]:
            return u'缺失值'
        else:
            if len(ICRIdentity) >= 1:
                for i in ICRIdentity:
                    marital_state = i.get("maritalState")
                    if marital_state not in null_type_list and marital_state in marital_state_list:
                        return marital_state
                    else:
                        return u'缺失值'
                return u'缺失值'
            else:
                return u'缺失值'
    except:
        return u'缺失值'


if __name__ == "__main__":
    file_obj = open(r'../data/IG/IG03_MariState/IC_DSJ.json', 'r')
    content = file_obj.read()
    IC_DSJ = json.loads(content, strict=False)
    aa = getIG03()
    print aa

result = getIG03()

